package com.isman.placeslist;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;

public class PageCategories extends Activity {
	private ExpandableListView _expList;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.page_categories);
		
		_expList = (ExpandableListView)findViewById(R.id.exp_categories_list);
		final ItemAdapter itemAdapter = new ItemAdapter();
		_expList.setAdapter(itemAdapter);
	}
	
	public class ItemAdapter extends BaseExpandableListAdapter {
        // Sample data set.  children[i] contains the children (String[]) for groups[i].
        private String[] groups = { "Hotel", "Restorant", "Traval", "Shop" };
        private String[][] children = {
                { "Arnold", "Barry", "Chuck", "David" },
                { "Ace", "Bandit", "Cha-Cha", "Deuce" },
                { "Fluffy", "Snuggles" },
                { "Goldy", "Bubbles" }
        };
        
        LayoutInflater inflater;
        public ItemAdapter(){
        	inflater = LayoutInflater.from(PageCategories.this);
        }
		@Override
		public Object getChild(int arg0, int arg1) {
			return null;
		}
		@Override
		public long getChildId(int arg0, int arg1) {
			// TODO Auto-generated method stub
			return 0;
		}
		@Override
		public View getChildView(int arg0, int arg1, boolean arg2, View arg3,
				ViewGroup arg4) {
			View view = inflater.inflate(R.layout.inc_item_group_item, null);
			view.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					startActivity(new Intent(PageCategories.this,PagePlaceList.class));
					
				}
			});
			TextView textView = (TextView)view.findViewById(R.id.lbl_item_grop_name);
			textView.setText(children[arg0][arg1]);
			return view;
		}
		@Override
		public int getChildrenCount(int arg0) {
			// TODO Auto-generated method stub
			return children[arg0].length;
		}
		@Override
		public Object getGroup(int arg0) {
			// TODO Auto-generated method stub
			return null;
		}
		@Override
		public int getGroupCount() {
			// TODO Auto-generated method stub
			return groups.length;
		}
		@Override
		public long getGroupId(int arg0) {
			// TODO Auto-generated method stub
			return 0;
		}
		@Override
		public View getGroupView(int arg0, boolean arg1, View arg2,
				ViewGroup arg3) {
			View view = inflater.inflate(R.layout.inc_item_grop, null);
			TextView textView = (TextView)view.findViewById(R.id.lbl_item_grop_name);
			textView.setText(groups[arg0]);
			textView = (TextView)view.findViewById(R.id.lbl_item_group_count);
			textView.setText(children[arg0].length+"");
			return view;
		}
		@Override
		public boolean hasStableIds() {
			return true;
		}
		@Override
		public boolean isChildSelectable(int arg0, int arg1) {
			// TODO Auto-generated method stub
			return true;
		}

    }
}
